<?php


namespace App\Http\Middleware;

use App\Exceptions\ApiException;
use App\Models\SysConfig;
use Closure;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use App\Models\AuthRule as AuthRuleModel;
use App\Engine\TokenService;

class CheckCms
{
    public function handle($request, Closure $next)
    {
        $rule=TokenService::getManageRule();
        $url=$request->path();

        AuthRuleModel::insert_route($url);
        $development_mode=SysConfig::getValue('development_mode');

        if(!in_array($url,$rule)&&$development_mode==0){
            throw new ApiException("没有权限");
        }

        return $next($request);
    }

}
